'use client'; import { useState } from 'react'; import { useRouter } from 'next/navigation'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; import { AlertCircle, ArrowLeft, Mail } from 'lucide-react'; import { Alert, AlertDescription } from '@/components/ui/alert'; import { useToast } from '@/hooks/use-toast'; import { useTranslations } from "next-intl"; import Link from 'next/link'; interface ForgotPasswordFormProps { locale: string; } export default function ForgotPasswordForm({ locale }: ForgotPasswordFormProps) { const [email, setEmail] = useState(''); const [isLoading, setIsLoading] = useState(false); const [isSuccess, setIsSuccess] = useState(false); const [error, setError] = useState(''); const { toast } = useToast(); const router = useRouter(); const t = useTranslations("auth.forgotPassword"); const tErrors = useTranslations("auth.errors"); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setIsLoading(true); setError(''); try { const response = await fetch('/api/auth/forgot-password', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ email, locale, }), }); const data = await response.json(); if (response.ok) { setIsSuccess(true); toast({ title: t('emailSent'), description: '请检查您的邮箱以重置密码。', }); } else { setError(data.error || tErrors('networkError')); } } catch (error) { setError(tErrors('networkError')); } finally { setIsLoading(false); } }; if (isSuccess) { return (
{t('checkEmailAt')}
{email}
{t('noEmailReceived')}
{t('agreeToTerms')}